package easyjava.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Example;

import easyjava.hibernate.bean.Student;

public class ExampleDemo {

	public static void main(String[] args) {

		          try{
		        	  SessionFactory sf=new Configuration().configure().buildSessionFactory();
		        	  Session session =sf.openSession();
		        	  
		        	  Student student =new Student();
		        	  student.setFirstname("ɰ");
		        	  student.setGender("Ů");
		        	  
		        	  Example studentExample =Example.create(student);
		        	  studentExample.excludeZeroes();
		        	  
		        	  Criteria criteria =session.createCriteria(Student.class);
		        	  criteria.add(studentExample);
		        	  
		        	  List<Student> students =criteria.list();
		        	  for(Object obj :students){
		        		  System.out.println(obj);
		        	  }
		        	  
		        	  
		        	  
		          }catch(HibernateException e){
		        	  e.printStackTrace();
		          }
		          
	}

}
